﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MarioMapEditor
{
    class PicBox
    {
        // Public
        public const int ZOOM = 2;
        public const int DIS = 16;

        public int pX, pY, lX, lY, objType, objIndex;
        public static int index;

        public PicBox(int objType, int lX, int lY)
        {
            PicBox.index++;
            this.objType = objType;
            this.lX = lX;
            this.lY = lY;
            this.objIndex = PicBox.index;
        }

        public void setPostion(int pX, int pY)
        {
            this.pX = pX/ZOOM;
            this.pY = pY/ZOOM;
        }

        public PictureBox createPic()
        {
            int boxSize = DIS*ZOOM;
            PictureBox pic = new PictureBox();
            pic.Name = "box_" + this.objIndex.ToString();
            pic.Location = new System.Drawing.Point(this.lX, this.lY);
            pic.Size = new System.Drawing.Size(boxSize, boxSize);
            pic.SizeMode = PictureBoxSizeMode.StretchImage;
            pic.Image = global::MarioMapEditor.Properties.Resources.brick;
            pic.MouseDoubleClick += new MouseEventHandler(this.picBoxMouseDoubleClick);
            return pic;
        }

        public void picBoxMouseDoubleClick(object sender, MouseEventArgs e)
        {
            if(MarioMapEditor.mainFrm.ActiveForm.Controls.Count > 0)
            {
                foreach (Control c in MarioMapEditor.mainFrm.ActiveForm.Controls.Find("box_" + this.objIndex, true))
                {
                    c.Dispose();
                }
            }
        }

        ~PicBox() { }
    }
}
